<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="daily"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
        <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
        <script src="/js/plugins/ckeditor/ckeditor.js"></script>
    <style type="text/css">
        .modal-body {
            max-height: 750px;
            overflow-y: auto;
        }
        .modal-body img {
            width: 100%;
        }
    </style>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">日报管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/daily/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="javascript:" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>标题</th>
                    <th>摘要</th>
                    <th>图片</th>
                    <th>发布时间</th>
                    <th>资讯分类</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.title}</td>
                        <td>${entity.brief}</td>
                        <td><img src="${entity.coverUrl}" width="100"/></td>
                        <td>${entity.releaseTime?string("yyyy-MM-dd")}</td>
                        <td>${entity.information.name}</td>
                        <td>
                            <a role="button" class="btn btn-primary btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-sunglasses"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/daily/saveOrUpdate.do" method="post"
                      enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">摘要：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="brief"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">图片：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100%"/>
                            <input type="file" class="form-control" name="img"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">资讯分类：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="information.id">
                            <#list informations as i>
                                <option value="${i.id}">${i.name}</option>
                            </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-4 control-label">发布时间：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="releaseTime"
                                   onclick="WdatePicker({readOnly:true,maxDate:new Date()});"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea name="dailyContent.content" id="ckeditor"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>


<div id="contentModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">日报内容</h4>
            </div>
            <div class="modal-body contentBody">
            </div>
            <div class="modal-footer">
                <a href="javascript:" class="btn btn-info" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        //被禁用的查看内容代码
       /* $(".contentBtn").click(function () {
            //拿到隐藏起来的参数id
            var id = $(this).data("tid");
            //点击的时候发送异步请求，获取到当前的游记的内容
            $.get("/daily/conent.do?id="+id,function (data) {
                //拿到回调的参数的时候，将这个参数赋值到模态窗的文本框中
                $(".contentBody").html(data);
                //打开模态窗
                $("#contentModal").modal("show");
            })
        })*/

        $(".inputBtn").click(function () {
            //打开模态窗之前先清空掉数据
            edt.setData('');
            $("#editForm input").val("");
            $("#coverUrl").attr("src","");
            //拿到编辑按钮上面所带有的json数据
            var json = $(this).data("json")
            //判断是新增还是编辑按钮点击的事件
            if(json){
                $.get("/daily/conent.do?id="+json.id,function (data) {
                    edt.setData(data);//渲染文本框中的内容
                })
                //编辑事件
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='title']").val(json.title);
                $("#editForm input[name='brief']").val(json.brief);
                $("#editForm input[name='releaseTime']").val(json.releaseTime);
                $("#editForm select[name='information.id']").val(json.informationId);
                $("#coverUrl").attr("src",json.coverUrl);
            }
            setTimeout(function () {
                $("#inputModal").modal("show");
            },500);
        })

        //初始化一个CKEDITOR
        var edt = CKEDITOR.replace("ckeditor");

        //给表单的保存按钮绑定点击事件
        $(".submitBtn").click(function () {
            //将富文本框中的数据赋值到表单提交参数上面
            $("#ckeditor").html(edt.getData());

            $("#editForm").ajaxSubmit(function (data) {
                if(data.success){
                    window.location.reload();
                }else{
                    alert(data.msg);
                }
            })
        })
    })
</script>
</body>
</html>